package nio;

import java.nio.ByteBuffer;

public class Demo2 {

    public static void main(String[] args) {

        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        String str = "libofei";
        byteBuffer.put(str.getBytes());
        //开启读模式
        byteBuffer.flip();
        byte[] bytes = new byte[byteBuffer.limit()];
        byteBuffer.get(bytes,0,2);
        System.out.println(new String(bytes,0,bytes.length));
        byteBuffer.mark();//打印标记
        System.out.println(new String(bytes,0,2));
        System.out.println(byteBuffer.position());
        byteBuffer.reset();//还原到Mark位置
        byteBuffer.get(bytes,2,2);
        System.out.println(new String(bytes,2,2));
        byteBuffer.reset();
        System.out.println(byteBuffer.position());
    }
}
